home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93a.txt / 000066_icon-group-sender _Sun Feb 14 17:28:21 1993.msg < prev    next >
Internet Message Format  |  1993-04-21  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Sun, 14 Feb 1993 16:48:37 MST
  2. Date: Sun, 14 Feb 93 17:28:21 CST
  3. From: "Richard L. Goerwitz" <goer@midway.uchicago.edu>
  4. Message-Id: <9302142328.AA06789@midway.uchicago.edu>
  5. To: icon-group@cs.arizona.edu
  6. Subject: novicy question
  7. Status: R
  8. Errors-To: icon-group-errors@cs.arizona.edu
  9.  
  10.  
  11. > I am trying to write a procedure that given a string looks to see
  12. > if there are any curly braces and cuts out whatever is between them.
  13. >
  14. > procedure  foo (line)
  15. >
  16. > line_ptr := 0    #  initialize a line ptr
  17. > com_set := '{}'  #  establish a cset of the things of interest
  18. >    line ? {
  19. >        if not find(com_set)
  20. >        then return line  #  if there is no curly return it
  21. >        else {
  22. >            temp := inline(tab(upto(comset))) #scissor out
  23. >            return temp    # the stuff between curlies
  24. >            }
  25. >        }
  26. >end # foo
  27.  
  28. The short answer is that you should just try
  29.  
  30. local s2
  31. s2 := ""
  32. s ? {
  33.     while s2 ||:= tab(find("{")) do {
  34.     move(1)
  35.     tab(find("}")+1)
  36.     }
  37.     s2 ||:= tab(0)
  38. }
  39. return s2
  40.  
  41. But this assumes that braces are never nested (as in "hello { the { re } }").
  42. If the braces can be nested, then read up on how to use bal().  If this func-
  43. tion is difficult for you to learn to use, then join the club :-), and post
  44. again with with other questions.  There's no rule against asking beginners'
  45. questions here!  Actually, they tend to spawn some interesting discussions.
  46.  
  47. If you're taking an introductory CS course, watch out.  Your profs may be ex-
  48. pecting you to handle (in addition to nesting) cases where the input is er-
  49. roneous, i.e. "hello { there " (i.e. with no right brace).  You might as well
  50. be warned now, and not have to submit to this rite of passage :-).  After all,
  51. you get browny points for finding out about and using this mailing list.
  52.  
  53. -Richard Goerwitz
  54.